package de.karlNet.sshTray.model;

import java.io.IOException;

import de.karlNet.sshTray.controller.SettingsController;

public class Connection {
	private Long id;
	private String username = "";
	private String title;
	private String host;
	private Type type;

	public Type getType() {
		return type;
	}

	public Connection setType(Type type) {
		this.type = type;
		return this;
	}

	public void connect() {
		String command = this.type.getCmdToExecute() + " " + this.username + " " + this.host;
		
//		String command = SettingsController.getSettings().loadSettings().getTerminalPath() + " "
//				+ (this.username.isEmpty()?"":this.username) + "@" + this.host;
		Runtime rt = Runtime.getRuntime();
		try {
			Process pr = rt.exec(command);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public boolean equals(Object o) {
		if (o instanceof Connection) {
			return (((Connection) (o)).id.equals(this.id));
		}
		return false;
	}

	public String getHost() {
		return host;
	}

	public Long getId() {
		return id;
	}

	public String getTitle() {
		return title;
	}

	public String getUsername() {
		return username;
	}

	public Connection setHost(String host) {
		this.host = host;
		return this;
	}

	public Connection setId(Long id) {
		this.id = id;
		return this;
	}
	
	public Connection setId(String id) {
		if(id.isEmpty()) 
			return this;
		this.id = Long.parseLong(id);
		return this;
	}

	public Connection setTitle(String title) {
		this.title = title;
		return this;
	}

	public Connection setUsername(String username) {
		this.username = username;
		return this;
	}
}
